package com.bsfcs.rag.repository;

import com.bsfcs.rag.entity.WorkHour;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface WorkHourRepository extends JpaRepository<WorkHour, String> {
    
    /**
     * 根据任务ID查找所有工时记录
     * @param taskId 任务ID
     * @return 工时记录列表
     */
    @Query("SELECT w FROM WorkHour w WHERE w.parentId = :taskId")
    List<WorkHour> findByParentId(@Param("taskId") String taskId);
    
    /**
     * 根据任务ID列表查找所有工时记录
     * @param taskIds 任务ID列表
     * @return 工时记录列表
     */
    @Query("SELECT new com.bsfcs.rag.entity.WorkHour(w.id, w.parentId, w.registrant, w.job_category, w.describe, w.job_date, " +
            "w.job_duration, w.start_time, w.end_time, w.create_time, w.output, w.registrant_deptname)  FROM WorkHour w WHERE w.parentId IN :taskIds")
    List<WorkHour> findByIds(@Param("taskIds") List<String> taskIds);
}